package com.timmy.mvpdemo.presenter;

import com.timmy.mvpdemo.interfa.RequestView;
import com.timmy.mvpdemo.interfa.TestCallback;
import com.timmy.mvpdemo.model.RequestMode;

/**
 * Created by Timmy on 2017/12/10.
 */

public class MainActivityPresenter {
    private RequestView mView;
    private final RequestMode mMode;

    public MainActivityPresenter() {
        mMode = new RequestMode();
    }

    public void clickRequest() {

        mView.requestLoading();

        mMode.request(new TestCallback() {
            @Override
            public void onSuccess() {
                mView.resultSuccess("成功");
            }

            @Override
            public void onFaild() {
                mView.resultFailure("失败");
            }
        });
    }

    /**
     * 绑定
     *
     * @param view
     */
    public void attach(RequestView view) {
        this.mView = view;
    }

    /**
     * 解除绑定
     */
    public void detach() {
        mView = null;
    }
    /**
     * 取消网络请求
     */
    public void interruptHttp(){
        mMode.interruptHttp();
    }
}
